package com.xiaoshuidi.cloud.module.rooms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.nonIntelligentDevice.vo.RoomDevicePriceVO;
import com.xiaoshuidi.cloud.module.rooms.enums.DevicePriceType;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomDevicePriceMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomDevicePrice;
import com.xiaoshuidi.cloud.module.rooms.repository.IotRoomDevicePriceRepository;
import com.xiaoshuidi.cloud.module.rooms.service.IRoomDevicePriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 水电费设置表 服务实现类
 * </p>
 *
 * @author James
 * @since 2023-06-07
 */
@Service
public class RoomDevicePriceServiceImpl extends ServiceImpl<RoomDevicePriceMapper, RoomDevicePrice> implements IRoomDevicePriceService {

    @Autowired
    IotRoomDevicePriceRepository iotRoomDevicePriceRepository;

    @Override
    public CommonResult<String> addConfig(RoomDevicePriceVO roomDevicePriceVO) {
        RoomDevicePrice roomDevicePrice = new RoomDevicePrice();
        roomDevicePrice.setBz(roomDevicePriceVO.getBz());
        roomDevicePrice.setDeptId(roomDevicePriceVO.getDeptId());
        roomDevicePrice.setElectricityPrice(roomDevicePriceVO.getElectricityPrice());
        roomDevicePrice.setColdWorterPrice(roomDevicePriceVO.getColdWorterPrice());
        roomDevicePrice.setHotWorterPrice(roomDevicePriceVO.getHotWorterPrice());
        roomDevicePrice.setPngPrice(roomDevicePriceVO.getPngPrice());
        roomDevicePrice.setType(DevicePriceType.DEVICE_PRICE_UNSTEP.getCode());
        iotRoomDevicePriceRepository.addConfig(roomDevicePrice);
        return CommonResult.success("添加成功");
    }

    @Override
    public CommonResult<PageResult<RoomDevicePriceVO>> findAll(Integer pageSize, Integer pageNum) {
        // todo @黄光辉 不要把逻辑都写到repository层
        PageResult<RoomDevicePriceVO> pageResult = iotRoomDevicePriceRepository.findAll(pageSize, pageNum);
        return CommonResult.success(pageResult);
    }

    @Override
    public CommonResult<String> deleteConfig(Long devicePriceId) {
        return iotRoomDevicePriceRepository.deleteConfig(devicePriceId);
    }

    @Override
    public CommonResult<String> updateConfig(RoomDevicePriceVO roomDevicePriceVO) {
        RoomDevicePrice roomDevicePrice = new RoomDevicePrice();
        roomDevicePrice.setId(roomDevicePriceVO.getId());
        roomDevicePrice.setBz(roomDevicePriceVO.getBz());
        roomDevicePrice.setDeptId(roomDevicePriceVO.getDeptId());
        roomDevicePrice.setElectricityPrice(roomDevicePriceVO.getElectricityPrice());
        roomDevicePrice.setColdWorterPrice(roomDevicePriceVO.getColdWorterPrice());
        roomDevicePrice.setHotWorterPrice(roomDevicePriceVO.getHotWorterPrice());
        roomDevicePrice.setPngPrice(roomDevicePriceVO.getPngPrice());
        roomDevicePrice.setType(DevicePriceType.DEVICE_PRICE_UNSTEP.getCode());
        iotRoomDevicePriceRepository.updateConfig(roomDevicePrice);
        return CommonResult.success("修改成功");
    }
}
